package com.yc.tomcat.impl;

import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

public class PostServlet extends HttpServletImpl{

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        PrintWriter out = response.getWriter();
        response.setContentType("text/html;charset=utf-8");
        String a = request.getParameter("a");
        String b = request.getParameter("b");
        String op = request.getParameter("op");
        int result = 0;
        if("1".equals(op)){
            result = Integer.parseInt(a) + Integer.parseInt(b);
        } else if("2".equals(op)){
            result = Integer.parseInt(a) - Integer.parseInt(b);
        }
        out.println(String.format("%s %s %s = %d", a, op, b, result));
    }
}
